package com.project;

public class EatFood {
    private int foodNum = 25;

    Thread thread01 = new Thread(){
        int A = 0;
        public void run(){
            while (true){
                foodNum -= 1;
                if (foodNum <= 0){
                    return;
                }
                try {
                    Thread.sleep(3000);
                    A += 1;
                    System.out.println("小明吃了：" + A + "饺子");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };

    Thread thread02 = new Thread(){
        int B = 0;
        public void run(){
            while (true){
                foodNum -= 1;
                if (foodNum < 0){
                    return;
                }
                try {
                    Thread.sleep(5000);
                    B += 1;
                    System.out.println("大壮吃了：" + B + "饺子");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };




    public static void main(String[] args) {
        EatFood eat = new EatFood();
        eat.thread01.start();
        eat.thread02.start();
    }
}
